<?php


use App\Library\Utils\Password as PasswordUtil;
use Phinx\Seed\AbstractSeed;
use Phalcon\Text;
use Faker\Factory as FakerFactory;

class AccountSeeder extends AbstractSeed
{
    /**
     * Run Method.
     *
     * Write your database seeder using this method.
     *
     * More information on writing seeders is available here:
     * https://book.cakephp.org/phinx/0/en/seeding.html
     */
    public function run()
    {
        $faker = FakerFactory::create('zh_CN');

        $rows = [];
        for ($i = 0; $i < 100; $i++) {
            $salt = PasswordUtil::salt();
            $email = $faker->email;
            while (strlen($email) >= 30) {
                $email = $faker->email;
            }
            $rows[] = [
                'email' => $email,
                'phone' => $faker->phoneNumber,
                'password' => PasswordUtil::hash(Text::random(Text::RANDOM_NOZERO), $salt),
                'salt' => $salt,
                'deleted' => 0,
                'create_time' => $faker->unixTime,
                'update_time' => $faker->unixTime
            ];
        }
        $this->table('kg_account')->insert($rows)->saveData();
    }
}
